package c.e.a.c.x;

import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.TimeInterpolator;
import android.animation.ValueAnimator;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.widget.EditText;
import com.google.android.material.textfield.TextInputLayout;
import com.google.android.material.textfield.TextInputLayout.f;
import com.google.android.material.textfield.TextInputLayout.g;

/* compiled from: ClearTextEndIconDelegate */
public class a extends m {
    public final TextWatcher d = new a();
    public final OnFocusChangeListener e = new b();
    public final f f = new c();
    public final g g = new d();
    public AnimatorSet h;
    public ValueAnimator i;

    /* compiled from: ClearTextEndIconDelegate */
    public class a implements TextWatcher {
        public void afterTextChanged(Editable editable) {
            if (a.this.a.getSuffixText() == null) {
                a.this.e(editable.length() > 0);
            }
        }

        public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
        }

        public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
        }
    }

    /* compiled from: ClearTextEndIconDelegate */
    public class b implements OnFocusChangeListener {
        public void onFocusChange(View view, boolean z) {
            boolean z2 = true;
            int isEmpty = TextUtils.isEmpty(((EditText) view).getText()) ^ 1;
            a aVar = a.this;
            if (isEmpty == 0 || !z) {
                z2 = false;
            }
            aVar.e(z2);
        }
    }

    /* compiled from: ClearTextEndIconDelegate */
    public class e implements OnClickListener {
        public void onClick(View view) {
            Editable text = a.this.a.getEditText().getText();
            if (text != null) {
                text.clear();
            }
        }
    }

    /* compiled from: ClearTextEndIconDelegate */
    public class c implements f {
        /* JADX WARNING: Missing block: B:6:0x0019, code skipped:
            if ((r0.getText().length() > 0 ? 1 : null) != null) goto L_0x001d;
     */
        public void a(com.google.android.material.textfield.TextInputLayout r5) {
            /*
            r4 = this;
            r0 = r5.getEditText();
            r1 = r0.hasFocus();
            r2 = 1;
            r3 = 0;
            if (r1 == 0) goto L_0x001c;
        L_0x000c:
            r1 = r0.getText();
            r1 = r1.length();
            if (r1 <= 0) goto L_0x0018;
        L_0x0016:
            r1 = 1;
            goto L_0x0019;
        L_0x0018:
            r1 = 0;
        L_0x0019:
            if (r1 == 0) goto L_0x001c;
        L_0x001b:
            goto L_0x001d;
        L_0x001c:
            r2 = 0;
        L_0x001d:
            r5.setEndIconVisible(r2);
            r5.setEndIconCheckable(r3);
            r5 = c.e.a.c.x.a.this;
            r5 = r5.e;
            r0.setOnFocusChangeListener(r5);
            r5 = c.e.a.c.x.a.this;
            r5 = r5.d;
            r0.removeTextChangedListener(r5);
            r5 = c.e.a.c.x.a.this;
            r5 = r5.d;
            r0.addTextChangedListener(r5);
            return;
            */
            throw new UnsupportedOperationException("Method not decompiled: c.e.a.c.x.a$c.a(com.google.android.material.textfield.TextInputLayout):void");
        }
    }

    /* compiled from: ClearTextEndIconDelegate */
    public class d implements g {
        public void a(TextInputLayout textInputLayout, int i) {
            EditText editText = textInputLayout.getEditText();
            if (editText != null && i == 2) {
                editText.removeTextChangedListener(a.this.d);
                if (editText.getOnFocusChangeListener() == a.this.e) {
                    editText.setOnFocusChangeListener(null);
                }
            }
        }
    }

    public a(TextInputLayout textInputLayout) {
        super(textInputLayout);
    }

    public void a() {
        this.a.setEndIconDrawable(b.b.d.a.a.b(this.b, 2131231142));
        TextInputLayout textInputLayout = this.a;
        textInputLayout.setEndIconContentDescription(textInputLayout.getResources().getText(2131689750));
        this.a.setEndIconOnClickListener(new e());
        this.a.a(this.f);
        textInputLayout = this.a;
        textInputLayout.g0.add(this.g);
        ValueAnimator ofFloat = ValueAnimator.ofFloat(new float[]{0.8f, 1.0f});
        ofFloat.setInterpolator(c.e.a.c.c.a.d);
        ofFloat.setDuration(150);
        ofFloat.addUpdateListener(new e(this));
        ValueAnimator ofFloat2 = ValueAnimator.ofFloat(new float[]{0.0f, 1.0f});
        TimeInterpolator timeInterpolator = c.e.a.c.c.a.a;
        ofFloat2.setInterpolator(timeInterpolator);
        ofFloat2.setDuration(100);
        ofFloat2.addUpdateListener(new d(this));
        AnimatorSet animatorSet = new AnimatorSet();
        this.h = animatorSet;
        animatorSet.playTogether(new Animator[]{ofFloat, ofFloat2});
        this.h.addListener(new b(this));
        ValueAnimator ofFloat3 = ValueAnimator.ofFloat(new float[]{1.0f, 0.0f});
        ofFloat3.setInterpolator(timeInterpolator);
        ofFloat3.setDuration(100);
        ofFloat3.addUpdateListener(new d(this));
        this.i = ofFloat3;
        ofFloat3.addListener(new c(this));
    }

    public void c(boolean z) {
        if (this.a.getSuffixText() != null) {
            e(z);
        }
    }

    public final void e(boolean z) {
        Object obj = this.a.l() == z ? 1 : null;
        if (z) {
            this.i.cancel();
            this.h.start();
            if (obj != null) {
                this.h.end();
                return;
            }
            return;
        }
        this.h.cancel();
        this.i.start();
        if (obj != null) {
            this.i.end();
        }
    }
}
